package com.rem.rabbitmq.ee.HdeadLetterQueue;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rem.rabbitmq.ee.RabbitMqUtils;

import java.util.Scanner;

/**
 * 死信队列
 * 某些时候由于特定的原因导致queue中的某些消息无法被消费 这样的消息如果没有后续的处理，就变成了死信，有死信自然就有了死信队列。
 * <p>
 * 死信来源
 * * 消息TTL过去
 * * 队列达到最大长度
 * * 消息被拒绝
 *
 * @author Rem
 * @date 2021-12-29
 */

public class MaxLengthProducer {


    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(RabbitMqUtils.EXCHANGE_NORMAL_MAXLENGTH, BuiltinExchangeType.DIRECT);

        System.err.println("开始发送消息...");
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();

            channel.basicPublish(RabbitMqUtils.EXCHANGE_NORMAL_MAXLENGTH, RabbitMqUtils.ROUTING_KEY_NORMAL_MAXLENGTH, null, message.getBytes());
            System.err.println("发送消息完毕" + message);
        }

    }


}
